from peewee import *

database = MySQLDatabase('zxzldb_new', **{'charset': 'utf8', 'use_unicode': True, 'host': 'localhost', 'user': 'root', 'password': '9999'})

class UnknownField(object):
    def __init__(self, *_, **__): pass

class BaseModel(Model):
    class Meta:
        database = database

class ContractInfo(BaseModel):
    company_addr = CharField()
    company_name = CharField()
    contract_date = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")])
    contract_num = CharField(primary_key=True)
    dev_activate_date = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")])
    dev_deadline_date = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")])
    expiry_time = IntegerField()
    legal_person = CharField()
    legal_person_phone = CharField(null=True)
    principal_person = CharField()
    principal_person_phone = CharField(null=True)
    purcha_num = IntegerField()
    tax_payer = CharField(null=True)

    class Meta:
        table_name = 'contract_info'

ContractInfo.create_table()

class ProdDevice(BaseModel):
    cpuid = CharField(column_name='cpuID', unique=True)
    devicesn = CharField(column_name='deviceSN', primary_key=True)
    device_stat = CharField(null=True)
    id = IntegerField(index=True)
    print_stat = IntegerField(constraints=[SQL("DEFAULT 0")], null=True)
    prod_date = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")])

    class Meta:
        table_name = 'prod_device'

ProdDevice.create_table()

class DevSettingInfo(BaseModel):
    alias = CharField(null=True)
    cali_quan = DecimalField(constraints=[SQL("DEFAULT 0.00")])
    contract_num = ForeignKeyField(column_name='contract_num', field='contract_num', model=ContractInfo)
    devicesn = ForeignKeyField(column_name='deviceSN', field='devicesn', model=ProdDevice, unique=True)
    pow_par = IntegerField(constraints=[SQL("DEFAULT 0")])
    trig_interval = DecimalField(constraints=[SQL("DEFAULT 10.00")])
    trig_num = IntegerField(constraints=[SQL("DEFAULT 10")])
    vacant_time = IntegerField(constraints=[SQL("DEFAULT 600")])
    vib_amp = DecimalField(constraints=[SQL("DEFAULT 0.00")])
    wat_fer_rate = FloatField(constraints=[SQL("DEFAULT 0")])
    weight_per_circ = DecimalField(constraints=[SQL("DEFAULT 0.00")])

    class Meta:
        table_name = 'dev_setting_info'

DevSettingInfo.create_table()

class DevStatusInfo(BaseModel):
    act_stat = IntegerField(constraints=[SQL("DEFAULT 0")])
    alias = CharField(null=True)
    contract_num = ForeignKeyField(column_name='contract_num', field='contract_num', model=ContractInfo)
    devicesn = ForeignKeyField(column_name='deviceSN', field='devicesn', model=ProdDevice, unique=True)
    duetime_prom = IntegerField(null=True)
    feed_line_ctrl = IntegerField(constraints=[SQL("DEFAULT 0")])
    feeder_empt = IntegerField(constraints=[SQL("DEFAULT 0")])
    flow_sens_dis = IntegerField(constraints=[SQL("DEFAULT 0")])
    moto_temp_hi = IntegerField(constraints=[SQL("DEFAULT 0")])
    online_stat = IntegerField(constraints=[SQL("DEFAULT 0")])
    pow_par = IntegerField(constraints=[SQL("DEFAULT 0")])
    str_line_dis = IntegerField(constraints=[SQL("DEFAULT 0")])
    ultr_sens_dis = IntegerField(constraints=[SQL("DEFAULT 0")])
    vib_stat = IntegerField(constraints=[SQL("DEFAULT 0")])
    wat_break = IntegerField(constraints=[SQL("DEFAULT 0")])
    wat_flow_hi = IntegerField(constraints=[SQL("DEFAULT 0")])
    wat_flow_lo = IntegerField(constraints=[SQL("DEFAULT 0")])
    wat_val_dis = IntegerField(constraints=[SQL("DEFAULT 0")])

    class Meta:
        table_name = 'dev_status_info'

DevStatusInfo.create_table()

class DeviceUser(BaseModel):
    employee_id = IntegerField(null=True)
    password = CharField()
    phone = CharField(null=True, unique=True)
    real_name = CharField()
    role = CharField(constraints=[SQL("DEFAULT 'Z'")])
    tax_payer = CharField(null=True)
    username = CharField(null=True, unique=True)

    class Meta:
        table_name = 'device_user'

DeviceUser.create_table()

class OperLogs(BaseModel):
    af_oper = CharField()
    bf_oper = CharField(null=True)
    oper_action = CharField()
    oper_col = CharField()
    oper_dev = CharField()
    oper_tb = CharField()
    oper_time = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")])
    oper_user = CharField()
    oper_user_company = CharField()

    class Meta:
        table_name = 'oper_logs'

OperLogs.create_table()

class UserLinkDev(BaseModel):
    alias = CharField()
    phone = CharField(null=True, unique=True)

    class Meta:
        table_name = 'user_link_dev'

UserLinkDev.create_table()

